package com.code.day07.Xc;

public class Consumer implements Runnable {
    private final BaoZiPu baoZiPu;
    public Consumer(BaoZiPu baoZiPu) {
        this.baoZiPu = baoZiPu;
    }
    @Override
    public void run() {
        for(;;){
            try{
                Thread.sleep(100L);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            synchronized (baoZiPu){
                if(!baoZiPu.isFlag()){
                    try{
                        baoZiPu.wait();
                    }catch(InterruptedException e){
                        e.printStackTrace();
                    }
                }
                baoZiPu.getCount();
                baoZiPu.setFlag(false);
                baoZiPu.notify();
            }
        }

    }
}
